// Package health provides health check functionality for the WePayKit application.
// This file implements an HTTP-based health checker.
package health

import (
	"net/http"
	"time"
)

// HTTPChecker implements a health checker for HTTP endpoints
type HTTPChecker struct {
	name    string
	url     string
	timeout time.Duration
}

// NewHTTPChecker creates a new HTTP checker
func NewHTTPChecker(name, url string, timeout time.Duration) *HTTPChecker {
	return &HTTPChecker{
		name:    name,
		url:     url,
		timeout: timeout,
	}
}

// Name returns the name of the checker
func (c *HTTPChecker) Name() string {
	return c.name
}

// Check performs the HTTP health check
func (c *HTTPChecker) Check() (Status, string) {
	client := &http.Client{
		Timeout: c.timeout,
	}
	
	resp, err := client.Get(c.url)
	if err != nil {
		return StatusDown, err.Error()
	}
	defer resp.Body.Close()
	
	// Consider 2xx status codes as UP
	if resp.StatusCode >= 200 && resp.StatusCode < 300 {
		return StatusUp, "HTTP endpoint is reachable"
	}
	
	return StatusDown, "HTTP endpoint returned status: " + resp.Status
}